﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Domain.MainModule.Entities;
using Infraestructure.Data.MainModule.UnitOfWork;
using Infraestructure.CrossCutting.Logging;
using Domain.MainModule.Addresses;
using Infraestructure.Data.MainModule.Repositories;

namespace Infraestructure.Data.MainModule.Tests.RepositoriesTests
{
    /// <summary>
    ///This is a test class for AddressRepositoryTest and is intended
    ///to contain all AddressRepositoryTest Unit Tests
    ///</summary>
    [TestClass()]
    public class AddressRepositoryTest : RepositoryTestsBase<Address>
    {
       
       public override System.Linq.Expressions.Expression<Func<Address, bool>> FilterExpression
        {
            get { return a => a.AddressId == TestConstants.Instance.ADDRESS_ID; }
        }

        public override System.Linq.Expressions.Expression<Func<Address, Guid>> OrderByExpression
        {
            get { return a => a.AddressId; }
        }

        /// <summary>
        ///A test for FindAddress
        ///</summary>
        [TestMethod()]
        public void FindAddressById_Invoke_Test()
        {
            //Arrange 
            IMainModuleUnitOfWork context = GetUnitOfWork();
            ITraceManager traceManager = this.GetTraceManager();
            IAddressRepository repository = new AddressRepository(context, traceManager);

            AddressIdSpecification spec = new AddressIdSpecification(TestConstants.Instance.ADDRESS_ID);

            //Act
            Address address = repository.FindAddress(spec);

            //Assert
            Assert.IsNotNull(address);
        }

        /// <summary>
        ///A test for FindAddress
        ///</summary>
        [TestMethod()]
        public void FindAddressByUserId_Invoke_Test()
        {
            //Arrange 
            IMainModuleUnitOfWork context = GetUnitOfWork();
            ITraceManager traceManager = this.GetTraceManager();
            IAddressRepository repository = new AddressRepository(context, traceManager);

            AddressUserIdSpecification spec = new AddressUserIdSpecification(TestConstants.Instance.USER_ID);

            //Act
            IEnumerable<Address> address = repository.FindAddresses(spec);

            //Assert
            Assert.IsNotNull(address);
            Assert.IsNotNull(address.First().City);
        }
    }
}
